//
//  LGGroupManageCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/24.
//

#import "LGGroupManageCell.h"

@interface LGGroupManageCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)UIButton *editButton;
/**   */
@property (nonatomic , strong)UIButton *deleteBtn;

@end

@implementation LGGroupManageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSString *title = dataDic[@"title"];
    if(title.length>12){
        title = [NSString stringWithFormat:@"%@...",[title substringToIndex:11]];
    }
    self.titleLabel.text = title;
    self.numberLabel.text = [NSString stringWithFormat:@"%@人",dataDic[@"count"]];
}


-(void)editButtonAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(editGroup:)]){
        [self.delegate editGroup:self.dataDic];
    }
}

-(void)deleteButtonAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(deleteGroup:)]){
        [self.delegate deleteGroup:self.dataDic];
    }
}


-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.tipView];
    [self.contentView addSubview:self.numberLabel];
    [self.contentView addSubview:self.editButton];
    [self.contentView addSubview:self.deleteBtn];
    [self.contentView addSubview:self.lineView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(32));
        make.centerY.equalTo(self.contentView);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(viewPix(3));
        make.width.height.equalTo(@(viewPix(12)));
        make.centerY.equalTo(self.contentView);
    }];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.editButton.mas_left).offset(-viewPix(7));
        make.centerY.equalTo(self.contentView);
    }];
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.deleteBtn.mas_left);
        make.centerY.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(28)));
    }];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(26));
        make.centerY.width.height.equalTo(self.editButton);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
    
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _numberLabel;
}

-(UIButton *)editButton{
    if(!_editButton){
        _editButton = [UIButton buttonWithImage:@"分组管理-编辑" selectImage:@"分组管理-编辑"];
        [_editButton addTarget:self action:@selector(editButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editButton;
}


-(UIButton *)deleteBtn{
    if(!_deleteBtn){
        _deleteBtn = [UIButton buttonWithImage:@"分组管理-删除" selectImage:@"分组管理-删除"];
        [_deleteBtn addTarget:self action:@selector(deleteButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteBtn;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#EFEFEF"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
